layui.use(['form', 'table'], function () {
    var $ = layui.jquery,
        form = layui.form,
        table = layui.table,
        layer=layui.layer;
    //form.render();
    /*    $.ajaxSetup({
            // 发送cookie
            xhrFields: {
                withCredentials: true
            },
            // 请求发送前
            beforeSend: function () {
                // 发送请求前，可以对data、url等处理
            },
            // 请求返回
            complete: function () {
                // 返回数据，根据数据调转页面等
            }
        });*/

    $(function () {
        $.ajax({
            url: devUrl + '/api/device/admin/selectByDeviceId',
            type: "get",
            data: {deviceId:$("#deviceid").val()},
            dataType: "json",
            success: function (data) {

                $("[name='deviceNumber']").val(data.data.devicenumber);
                $("[name='rowNumber']").val(data.data.rownumber);
                $("[name='columnNumber']").val(data.data.columnnumber);
                $("[name='deviceName']").val(data.data.devicename);
                $("[name='stockMaxQty']").val(data.data.stockmaxqty);
                $("[name='stockFlag']").val(data.data.stockflag);
                $("option[value='"+data.data.sortingid+"']").prop("selected","selected");
                //$("option[value='"+data.data.sortingid+"']").html();
                $("[name='sortingGrComRate']").val(data.data.sortinggrcomrate);
                $("[name='sortingGoodsComRate']").val(data.data.sortinggoodscomrate);
                $("option[value='"+data.data.operatorsid+"']").prop("selected","selected");
                $("[name='operatorsGrComRate']").val(data.data.operatorsgrcomrate);
                $("[name='partnersId']>option[value='"+data.data.partnersid+"']").prop("selected","selected");
                $("[name='partnersGrComRate']").val(data.data.partnersgrcomrate);
                $("[name='partnersGoodsComRate']").val(data.data.partnersgoodscomrate);
                $("option[value='"+data.data.venuesid+"']").prop("selected","selected");
                $("[name='province']").val(data.data.province);
                $("[name='city']").val(data.data.city);
                $("[name='area']").val(data.data.area);
                $("[name='address']").val(data.data.address);

                if(data.data.isflag == 2){
                    $("input[name=isFlag][value='1']").prop("checked","false");
                    $("input[name=isFlag][value='2']").prop("checked","true");
                }else {
                    $("input[name=isFlag][value='2']").prop("checked","false");
                    $("input[name=isFlag][value='1']").prop("checked","true");
                }

                form.render();
                // $("[name='isFlag'],[value='"+data.data.isflag+"']").checked = true;

            }
        })
    });

    $("#saveBtn").click(function () {
        let deviceid = $("#deviceid").val();
        if(deviceid != null && deviceid !== ''){
            $.ajax({
                url: devUrl + '/api/device/admin/saveOrUpdateDevice',
                data: {
                    deviceid:$("#deviceid").val(),
                    devicenumber : $("[name='deviceNumber']").val(),
                    rownumber : $("[name='rowNumber']").val(),
                    columnnumber : $("[name='columnNumber']").val(),
                    devicename : $("[name='deviceName']").val(),
                    stockmaxqty : $("[name='stockMaxQty']").val(),
                    stockflag : $("[name='stockFlag']").val(),
                    sortingid : $("[name='sortingId']").val(),
                    sortinggrcomrate : $("[name='sortingGrComRate']").val(),
                    sortinggoodscomrate : $("[name='sortingGoodsComRate']").val(),
                    operatorsid :$("[name='operatorsId']").val(),
                    operatorsgrcomrate : $("[name='operatorsGrComRate']").val(),
                    partnersid : $("[name='partnersId']").val(),
                    partnersgrcomrate : $("[name='partnersGrComRate']").val(),
                    partnersgoodscomrate : $("[name='partnersGoodsComRate']").val(),
                    venuesid : $("[name='venuesId']").val(),
                    province : $("[name='province']").val(),
                    city : $("[name='city']").val(),
                    area : $("[name='area']").val(),
                    address : $("[name='address']").val(),
                    isflag : $("[name='isFlag']").val(),
                    devicestatus:1
                },
                dataType: "json",
                type:"put",
                success: function (result) {
                    alert(result.msg)
                }
            })
        } else {
            $.ajax({
                url: devUrl + '/api/device/admin/addDevice',
                data: {
                    devicenumber : $("[name='deviceNumber']").val(),
                    rownumber : $("[name='rowNumber']").val(),
                    columnnumber : $("[name='columnNumber']").val(),
                    devicename : $("[name='deviceName']").val(),
                    stockmaxqty : $("[name='stockMaxQty']").val(),
                    stockflag : $("[name='stockFlag']").val(),
                    sortingid : $("[name='sortingId']").val(),
                    sortinggrcomrate : $("[name='sortingGrComRate']").val(),
                    sortinggoodscomrate : $("[name='sortingGoodsComRate']").val(),
                    operatorsid :$("[name='operatorsId']").val(),
                    operatorsgrcomrate : $("[name='operatorsGrComRate']").val(),
                    partnersid : $("[name='partnersId']").val(),
                    partnersgrcomrate : $("[name='partnersGrComRate']").val(),
                    partnersgoodscomrate : $("[name='partnersGoodsComRate']").val(),
                    venuesid : $("[name='venuesId']").val(),
                    province : $("[name='province']").val(),
                    city : $("[name='city']").val(),
                    area : $("[name='area']").val(),
                    address : $("[name='address']").val(),
                    isflag : $("[name='isFlag']").val(),
                    devicestatus:1
                },
                dataType: "json",
                type:"post",
                success: function (result) {
                    alert(result)
                }
            })
        }

    })









});